package com.itheima.reggie;

import com.itheima.reggie.utils.ValidateCodeUtils;
import org.springframework.util.AntPathMatcher;
import org.springframework.util.DigestUtils;

import java.util.HashMap;
import java.util.UUID;

public class Demo1 {

    public static void main(String[] args) {
        /*
            7e8efbbdffa14c66075fad90fed7d61688fff4e322d04c57af3e373f891c9b25
            1cffbfcc00ae32c79bf1a1552923fe6b2faaeb1bf9804d5fb22a9902bf71f9a5
            2955572f4b33107c020c137b56b548eb834bae6f269d4a3580be2bbfd1bf7081
         */
        //输入的密码，用户要登录
        String mima="1234567";
        //首先会根据用户名去数据库中查询出一个用户，获取用户的密文，截取密文中后32位，这个就是随机字符串
        //假设这个字符串就是数据库中查询出来的用户的密文
        String miwen = "7e8efbbdffa14c66075fad90fed7d61688fff4e322d04c57af3e373f891c9b25";
        //获取该密文的随机盐
        String salt = miwen.substring(32);
        //用户登录的时候输入的密码 + 数据库中密文相同的随机盐  得到了。
        String miwen2 = DigestUtils.md5DigestAsHex((mima + salt).getBytes()) + salt;
        System.out.println(miwen2);
        if(miwen2.equals(miwen)){
            System.out.println("success");
        }else{
            System.out.println("error");
        }
    }





    private static void md5Salt() {
        //对123456字符串进行加密，使用加随机盐的算法 达到每次加密后 密文都不一样。
        String randomStr = UUID.randomUUID().toString().replace("-","");
        String miwen = DigestUtils.md5DigestAsHex(("123456" + randomStr).getBytes()) + randomStr;
        System.out.println(miwen);
    }

    private static void method4() {
        Integer codeNum = ValidateCodeUtils.generateValidateCode(6);
        String codeStr = ValidateCodeUtils.generateValidateCode4String(6);
        System.out.println(codeNum);
        System.out.println(codeStr);
    }

    private static void method3() {
        String key = "username";

        HashMap<String, String> map1 = new HashMap<>();//线程1的map
        HashMap<String, String> map2 = new HashMap<>();//线程2的map
        HashMap<String, String> map3 = new HashMap<>();//线程3的map
        map1.put(key,"tom");
        map2.put(key,"linda");
        map3.put(key,"jerry");

        System.out.println(map1.get(key));
        System.out.println(map2.get(key));
        System.out.println(map3.get(key));
    }

    private static void method2() {
        System.out.println("/backend/**".contains("/backend/page/login/login.html"));//false
        AntPathMatcher PATH_MATCHER = new AntPathMatcher();

        //路径匹配器，支持通配符 **
        boolean match = PATH_MATCHER.match("/backend/**", "/backend/page/login/login.html");
        System.out.println(match);//true
    }

    private static void method1() {
        String s1 = DigestUtils.md5DigestAsHex("123456".getBytes());
        String s2 = DigestUtils.md5DigestAsHex("123456".getBytes());
        String s3 = DigestUtils.md5DigestAsHex("123456".getBytes());
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
    }
}
